package com.huey.utils.connect;


import feign.Client;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * 连接池配置
 * @author xubo
 * @date 2022/3/30 15:57
 */
@Configuration
public class OkHttpConfig {

    @Bean
    public OkHttpClient okHttpClient() {
        ConnectionPool connectionPool = new ConnectionPool(5, 10, TimeUnit.MINUTES);
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(50, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                .connectionPool(connectionPool);
        return builder.build();
    }
    /**
     * 配置自定义的Client
     *
     * @return
     */
    @Bean
    public Client kingdeeClient() {
        OkHttpClient httpClient = new OkHttpClient.Builder()
                //设置连接超时
                .connectTimeout(30, TimeUnit.SECONDS)
                //设置读超时
                .readTimeout(120, TimeUnit.SECONDS)
                //设置写超时
                .writeTimeout(120, TimeUnit.SECONDS)
                //是否自动重连
                .retryOnConnectionFailure(false)
                .connectionPool(new ConnectionPool(100, 5L, TimeUnit.MINUTES))
                .build();
       // return new KingdeeFilterClientInterceptor(new feign.okhttp.OkHttpClient(httpClient));
        return null;
    }


}
